<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-touch-fullscreen" content="yes">
		<meta name="format-detection" content="telephone=no;email=no">

		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" href="../../css/style.css">
		<title>我的收藏</title>
		<style>
			.mui-table-view .mui-media-object {
				max-width: 91px;
				height: 65px;
			}
			
			.mui-media-body {
				position: relative;
				color: #000;
			}
			
			.mui-media-body .news-time {
				margin-top: 10px;
			}
			
			.mui-media-body time {
				color: #999;
				font-size: 14px;
			}
		</style>
	</head>

	<body>
		<!-- 刷新容器 -->
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<!--数据列表-->
				<ul class="mui-table-view" id="myCollectionsUl">

				</ul>
			</div>
		</div>
		<!-- 缓存数据 -->
		<textarea id="listTemp" style="display: none;"></textarea>
		
		<script src="../../js/mui.min.js"></script>
		<script src="../../libs/zepto.min.js"></script>
		<script src="../../js/template.js"></script>
		<script src="../../js/common.js"></script>

		<!-- 评论模板 -->
		<script id="myCollections" type="text/html">
			{{each data as value i}}
			<li class="mui-table-view-cell mui-media" data-newsId="{{value.newsId}}" data-type="{{value.type}}">
				<div class="mui-slider-right mui-disabled">
					<a id={{value.id}} class="mui-btn mui-btn-red">删除</a>
				</div>
				<div class="mui-slider-handle">
					<a href="javascript:;">
						<img class="mui-media-object mui-pull-left" src="{{value.carouselImage}}" onerror="this.src='../../images/lauch/def/tw_def.png'">
						<div class="mui-media-body image-text">
							{{value.newsTitle}}
							<!--<p>{{value.abstractInfor}}</p>-->
							<div class="news-time"><time>{{value.releaseAtMinNumber}}</time></div>
						</div>
					</a>
				</div>
			</li>
			{{/each}}
		</script>

		<script>
			mui.init({
				swipeBack: true, //启用右滑关闭功能
				pullRefresh: {
					container: '#pullrefresh',
					up: {
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
			});
			mui.each($("#myCollectionsUl .image-text"), function() {
				if ($(this).height() < 65) {
					$(this).css("height", "65px");
					$(this).find(".news-time").addClass("pos");
				}
			});
			//添加night自定义事件监听
			/*window.addEventListener('night', function(event) {
				lkg.nightMode();
			});*/
			//添加read自定义事件监听
			window.addEventListener('read', function(event) {
				var currentType = plus.networkinfo.getCurrentType();
				var readMode = localStorage.getItem("readMode");
				if (readMode == 1) {
					if (currentType === plus.networkinfo.CONNECTION_WIFI) {
						showImg("#myCollectionsUl");
					} 
					else {
						hideImg("#myCollectionsUl");
					}
				} 
				else if (readMode == 2) {
					showImg("#myCollectionsUl");
				} 
				else if (readMode == 3) {
					hideImg("#myCollectionsUl");
				}
			});
			/**
			 * 上拉加载具体业务实现
			 */
			var startIndex = 0;

			function pullupRefresh() {
				var uuid = plus.device.uuid; //获取设备的唯一标识
				//setTimeout(function() {
				plus.nativeUI.showWaiting("", {width: "50px", height: "50px", background: "#efeff4", style: "black"});
				mui.ajax({
					url: baseUrl + '/my/sclis?devicesId=' + uuid + '&start=' + startIndex + '&length=5',
					dataType: 'json',
					type: 'get',
					success: function(data) {
						if (data.returnFlag == 0) {
							mui.each(data.data, function(index, value) {
								if (value.releaseAtMinNumber < 28800000) {
									value.releaseAtMinNumber = Humanize(value.releaseAtMinNumber);
								} else {
									value.releaseAtMinNumber = value.releaseAt;
								}
							});
							mui('#pullrefresh').pullRefresh().endPullupToRefresh(data.data.length == 0); //参数为true代表没有更多数据了。
							if (data.data.length > 0) {
								var html = template('myCollections', data);
								startIndex += data.data.length;
								$("#listTemp").html(html);
								var currentType = plus.networkinfo.getCurrentType();
								var readMode = localStorage.getItem("readMode");
								if (readMode == 1) {
									if (currentType === plus.networkinfo.CONNECTION_WIFI) {
										showImg("#listTemp");
									}
									else {
										hideImg("#listTemp");
									}
								} 
								else if (readMode == 2) {
									showImg("#listTemp");
								} 
								else if (readMode == 3) {
									hideImg("#listTemp");
								}
								document.getElementById('myCollectionsUl').innerHTML += html;
								//标签随文字段落高度自适应位置
								mui.each($("#myCollectionsUl .image-text"), function() {
									if ($(this).height() < 65) {
										$(this).css("height", "65px");
										$(this).find(".news-time").addClass("pos");
									}
								});
							}
							plus.nativeUI.closeWaiting();
						}
					},
					error: function(xhr, type, errorThrown) {
						//异常处理；
						throwGetNewsError();
					}
				});
				//}, 1000);
			}
			mui("#myCollectionsUl").on("tap", "li", function() {
				var newsId = $(this).attr('data-newsId');
				var type = $(this).attr("data-type");
				var href = null;
				if (type == 1) {
					href = 'images-details.html';
				} 
				else if(type == 3){
					href = 'vote-details.html';
				}
				else {
					href = 'news-details.html';
				}
				//打开详情页面          
				mui.openWindow({
					url: '../news/' + href,
					id: href,
					extras: {
						newsId: newsId
					},
					waiting: {
						autoShow: false
					},
					createNew: true //是否重复创建同样id的webview，默认为false:不重复创建，直接显示
				});
			});
			mui('#myCollectionsUl').on('tap', '.mui-btn', function(event) {
				var id = this.getAttribute('id');
				var elem = this;
				var li = elem.parentNode.parentNode;
				mui.ajax({
					url: baseUrl + '/my/delSC?scid=' + id,
					dataType: 'json',
					type: 'get',
					success: function(data) {
						if (data.returnFlag == 0) {
							li.parentNode.removeChild(li);
						}
					},
					error: function(xhr, type, errorThrown) {
						//异常处理；
						throwGetNewsError();
					}
				});
			});
			var btnArray = ['确认', '取消'];

			function refreshList() {
				startIndex = 0;
				document.getElementById('myCollectionsUl').innerHTML = "";
				mui('#pullrefresh').pullRefresh().pullupLoading();
				mui('#pullrefresh').pullRefresh().refresh(true);
			}
			if (mui.os.plus) {
				mui.plusReady(function() {
					setTimeout(function() {
						mui('#pullrefresh').pullRefresh().pullupLoading();
					}, 100);
				});
			} else {
				mui.ready(function() {
					mui('#pullrefresh').pullRefresh().pullupLoading();
				});
			}
		</script>
	</body>

</html>